/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente;

import javax.swing.JOptionPane;
import sop_corba.Callback;
import sop_corba.Juego;

/**
 *
 * @author familia
 */
public class Tablero extends javax.swing.JFrame {
    
   
    private Callback Callback;
    private CallbackImpl CallbackImpl;
    private Juego Juego;
    private String nombre;
    private int jugador;
    int x,y;
   
    public Tablero(Callback cllb,CallbackImpl cllbimpl,Juego juego, String login) {
        
        this.Callback = cllb;
        this.CallbackImpl = cllbimpl;
        this.Juego = juego;
        this.CallbackImpl.setPrincipal(this);
        initComponents();
        this.jLabel3.setText(login);
        
    }

    /*private Tablero() {
        initComponents();
    }*/

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        btn_1 = new javax.swing.JButton();
        btn_2 = new javax.swing.JButton();
        btn_3 = new javax.swing.JButton();
        btn_4 = new javax.swing.JButton();
        btn_5 = new javax.swing.JButton();
        btn_6 = new javax.swing.JButton();
        btn_7 = new javax.swing.JButton();
        btn_8 = new javax.swing.JButton();
        btn_9 = new javax.swing.JButton();
        btn_iniciar = new javax.swing.JButton();
        btn_estadisticas = new javax.swing.JButton();
        btn_salir = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Myriad Pro Light", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 204, 51));
        jLabel1.setText("Triqui");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Jugador:");

        jLabel3.setText("------");

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));

        btn_1.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_1ActionPerformed(evt);
            }
        });

        btn_2.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_2ActionPerformed(evt);
            }
        });

        btn_3.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_3ActionPerformed(evt);
            }
        });

        btn_4.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_4ActionPerformed(evt);
            }
        });

        btn_5.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_5ActionPerformed(evt);
            }
        });

        btn_6.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_6ActionPerformed(evt);
            }
        });

        btn_7.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_7ActionPerformed(evt);
            }
        });

        btn_8.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_8ActionPerformed(evt);
            }
        });

        btn_9.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        btn_9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_4, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_5, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_6, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_7, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_8, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_9, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_3, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_2, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_6, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_5, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_4, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_9, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_8, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_7, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        btn_iniciar.setText("Inicar Partida");
        btn_iniciar.setEnabled(false);
        btn_iniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_iniciarActionPerformed(evt);
            }
        });

        btn_estadisticas.setText("Estadisticas");

        btn_salir.setText("Salir");
        btn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salirActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Resultado");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 0, 51));
        jLabel5.setText("----");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(176, 176, 176)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(62, 62, 62)
                                .addComponent(btn_salir, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(btn_estadisticas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btn_iniciar, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                                    .addComponent(jLabel5))))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btn_iniciar)
                        .addGap(18, 18, 18)
                        .addComponent(btn_estadisticas)
                        .addGap(18, 18, 18)
                        .addComponent(btn_salir))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_1ActionPerformed
        
        x=0;
        y=0;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_1.setEnabled(false);
        if(jugador==1){
            btn_1.setText("X");
        }
        else if(jugador==2){
            btn_1.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_1ActionPerformed

    private void btn_2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_2ActionPerformed
        x=0;
        y=1;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_2.setEnabled(false);
        if(jugador==1){
            btn_2.setText("X");
        }
        else if(jugador==2){
            btn_2.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_2ActionPerformed

    private void btn_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_3ActionPerformed
        x=0;
        y=2;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_3.setEnabled(false);
        if(jugador==1){
            btn_3.setText("X");
        }
        else if(jugador==2){
            btn_3.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_3ActionPerformed

    private void btn_4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_4ActionPerformed
        x=1;
        y=0;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_4.setEnabled(false);
        if(jugador==1){
            btn_4.setText("X");
        }
        else if(jugador==2){
            btn_4.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_4ActionPerformed

    private void btn_5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_5ActionPerformed
       x=1;
        y=1;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_5.setEnabled(false);
        if(jugador==1){
            btn_5.setText("X");
        }
        else if(jugador==2){
            btn_5.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_5ActionPerformed

    private void btn_6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_6ActionPerformed
       x=1;
        y=2;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_6.setEnabled(false);
        if(jugador==1){
            btn_6.setText("X");
        }
        else if(jugador==2){
            btn_6.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_6ActionPerformed

    private void btn_7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_7ActionPerformed
       x=2;
        y=0;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_7.setEnabled(false);
        if(jugador==1){
            btn_7.setText("X");
        }
        else if(jugador==2){
            btn_7.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_7ActionPerformed

    private void btn_8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_8ActionPerformed
        x=2;
        y=1;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_8.setEnabled(false);
        if(jugador==1){
            btn_8.setText("X");
        }
        else if(jugador==2){
            btn_8.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_8ActionPerformed

    private void btn_9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_9ActionPerformed
       x=2;
        y=2;
        jugador = Callback.id();
        nombre = Callback.login();
        Juego.Operar_Casillas(x,y,jugador);
        btn_9.setEnabled(false);
        if(jugador==1){
            btn_9.setText("X");
        }
        else if(jugador==2){
            btn_9.setText("O");
        }
        Juego.Cargar(x, y, jugador, nombre);
    }//GEN-LAST:event_btn_9ActionPerformed

    private void btn_iniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_iniciarActionPerformed
        if(Juego.numJugadores()==2){
            
            Juego.Reiniciar();
            Juego.Iniciar_Partida();
        }
        else{
            JOptionPane.showMessageDialog(this,"No hay Jugadores Suficientes", "Mensaje",JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btn_iniciarActionPerformed

    private void btn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salirActionPerformed
       this.dispose();
    }//GEN-LAST:event_btn_salirActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Tablero.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Tablero.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Tablero.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Tablero.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new Tablero().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_1;
    private javax.swing.JButton btn_2;
    private javax.swing.JButton btn_3;
    private javax.swing.JButton btn_4;
    private javax.swing.JButton btn_5;
    private javax.swing.JButton btn_6;
    private javax.swing.JButton btn_7;
    private javax.swing.JButton btn_8;
    private javax.swing.JButton btn_9;
    private javax.swing.JButton btn_estadisticas;
    private javax.swing.JButton btn_iniciar;
    private javax.swing.JButton btn_salir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
    
    int Ganador(){
        if(Juego.Ganador()!=-1){
           btn_1.setEnabled(false);
           btn_2.setEnabled(false);
           btn_3.setEnabled(false);;
           btn_4.setEnabled(false);
           btn_5.setEnabled(false);
           btn_6.setEnabled(false);
           btn_7.setEnabled(false);
           btn_8.setEnabled(false);
           btn_9.setEnabled(false);
           return Juego.Ganador();
        }
        return -1;
        
    }
    void Actualizar_Tablero(int n, int m, int id, String nom) {
         nombre = nom;
        jugador = id;        
        if(n==0 && m==0){
            btn_1.setEnabled(false);
            if(jugador==1){
                btn_1.setText("X");
            }
            else if(jugador==2){
                btn_1.setText("O");
            }
        }        
        else if(n==0 && m==1){
            btn_2.setEnabled(false);
            if(jugador==1){
               btn_2.setText("X");
            }
            else if(jugador==2){
                btn_2.setText("O");
            }
        }
        else if(n==0 && m==2){
            btn_3.setEnabled(false);
            if(jugador==1){
               btn_3.setText("X");
            }
            else if(jugador==2){
                btn_3.setText("O");
            }
        }
        else if(n==1 && m==0){
            btn_4.setEnabled(false);
            if(jugador==1){
               btn_4.setText("X");
            }
            else if(jugador==2){
                btn_4.setText("O");
            }
        }
        else if(n==1&& m==1){
            btn_5.setEnabled(false);
            if(jugador==1){
               btn_5.setText("X");
            }
            else if(jugador==2){
                btn_5.setText("O");
            }
        }
        else if(n==1 && m==2){
            btn_6.setEnabled(false);
            if(jugador==1){
               btn_6.setText("X");
            }
            else if(jugador==2){
                btn_6.setText("O");
            }
        }
        else if(n==2 && m==0){
            btn_7.setEnabled(false);
            if(jugador==1){
               btn_7.setText("X");
            }
            else if(jugador==2){
                btn_7.setText("O");
            }
        }
        else if(n==2 && m==1){
            btn_8.setEnabled(false);
            if(jugador==1){
               btn_8.setText("X");
            }
            else if(jugador==2){
                btn_8.setText("O");
            }
        }
        else if(n==2 && m==2){
            btn_9.setEnabled(false);
            if(jugador==1){
               btn_9.setText("X");
            }
            else if(jugador==2){
                btn_9.setText("O");
            }
        }
        
        if(Ganador()!=-1){
            jLabel5.setText("Ganador: "+nom);
            //Juego.registrarPartida(nom);
            btn_iniciar.setEnabled(true);
        }
        else if(Juego.Termianr_Partida()){
            jLabel5.setText("Empate");
            //Juego.registrarPartida("Empate");
            btn_iniciar.setEnabled(true);
        }
    }

    void Bloquear_Tablero() {
         btn_1.setEnabled(false);
        btn_2.setEnabled(false);
        btn_3.setEnabled(false);
        btn_4.setEnabled(false);
        btn_5.setEnabled(false);
        btn_6.setEnabled(false);
        btn_7.setEnabled(false);
        btn_8.setEnabled(false);
        btn_9.setEnabled(false);
    }

    void Desbloquear_Tablero() {
        if(btn_1.getText().equals("")){btn_1.setEnabled(true);}
        if(btn_2.getText().equals("")){btn_2.setEnabled(true);}
        if(btn_3.getText().equals("")){btn_3.setEnabled(true);}
        if(btn_4.getText().equals("")){btn_4.setEnabled(true);}
        if(btn_5.getText().equals("")){btn_5.setEnabled(true);}
        if(btn_6.getText().equals("")){btn_6.setEnabled(true);}
        if(btn_7.getText().equals("")){btn_7.setEnabled(true);}
        if(btn_8.getText().equals("")){btn_8.setEnabled(true);}
        if(btn_9.getText().equals("")){btn_9.setEnabled(true);}
    }

    void reiniciar() {
        btn_1.setEnabled(true);
        btn_2.setEnabled(true);
        btn_3.setEnabled(true);
        btn_4.setEnabled(true);
        btn_5.setEnabled(true);
        btn_6.setEnabled(true);
        btn_7.setEnabled(true);
        btn_8.setEnabled(true);
        btn_9.setEnabled(true);
        
        btn_1.setText("");
        btn_2.setText("");
        btn_3.setText("");
        btn_4.setText("");
        btn_5.setText("");
        btn_6.setText("");
        btn_7.setText("");
        btn_8.setText("");
        btn_9.setText("");
        
        
        
        
    }
}
